package com.polaris.live.popup

import android.content.Context
import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.StringUtils
import com.lxj.xpopup.core.BottomPopupView
import com.polaris.live.R
import com.polaris.live.adapter.ReportAdapter
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.util.NavigationBarUtils
import com.polaris.live.databinding.PopupSourceReportBinding
import com.polaris.live.resp.bean.ReportBean
import com.polaris.live.translation.R.string

/**
 * ReportPopup
 *
 * @author Created by 半仙 on 2023/10/26/026 20:56
 */
class ReportSourcePopup(
    context: Context,
    private val owner: LifecycleOwner?,
    private val nickName: String,
    private val viewModel: BaseViewModel,
    private val otherUserId: Long,
    private val objectId: Long? = null,
) :
    BottomPopupView(context) {

    private lateinit var mBinding: PopupSourceReportBinding

    private val mAdapter by lazy {
        ReportAdapter()
    }

    override fun getImplLayoutId(): Int {
        return R.layout.popup_source_report
    }

    override fun onCreate() {
        super.onCreate()
        mBinding = PopupSourceReportBinding.bind(popupImplView)
        mBinding.recycler.apply {
            adapter = mAdapter
            layoutManager = LinearLayoutManager(context)
        }
        mAdapter.setList(list)
        mBinding.tvReportUserName.text = nickName

        mAdapter.setOnItemClickListener { _, _, position ->
            val item = mAdapter.data[position]
            if (item.type != -1) {
                GlobalPopupManager.showOptionReport(
                    context,
                    owner,
                    viewModel,
                    nickName,
                    otherUserId,
                    item.type,
                    objectId
                )
            }
            dismiss()
        }

        NavigationBarUtils.setNavigationHeightIfTransparent(mBinding.recycler)
    }

    companion object {

        val list = mutableListOf(
            ReportBean(StringUtils.getString(string.video), 2),
            ReportBean(StringUtils.getString(string.live), 3),
            ReportBean(StringUtils.getString(string.cover), 6),
            ReportBean(StringUtils.getString(string.user_head), 4),
            ReportBean(StringUtils.getString(string.nickname), 1),
            ReportBean(StringUtils.getString(string.signature), 5),
            ReportBean(StringUtils.getString(string.chat_message), 7),
            ReportBean(StringUtils.getString(string.cancel), -1),
        )
    }
}